$(document).ready(function () {
    $("#enterBtn").click(enter);
});

function enter() {
    const uid = $("#uid").val();
    const group = $("#group").val();
    const ws = $("#ws").val();
    const type = $("#type").val();
    if (validateStr(uid)) {
        alert("请输入用户名！");
        return;
    }
    if (validateStr(ws)) {
        alert("请输入链接地址！");
        return;
    }
    if (validateStr(type)) {
        alert("请选择频道！");
        return;
    }
    localStorage.user = JSON.stringify({
        user: uid,
        group: group,
        ws: ws
    });
    window.location.href = type;
}

/**
 * 验证字符串是否为空：已经处理了空格、换行等
 * @param str
 * @returns {boolean}
 */
function validateStr(str) {
    return str.replace(/(^s*)|(s*$)/g, "").length == 0;
}